package com.zxj.camerapreview;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.media.AudioManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import cn.iotnova.opus.utils.OpusRecorderTask;
import cn.iotnova.rtc.Rtcclient;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = MainActivity.class.getName() ;

    private String APP_PATH;
    private String APP_RECORDER_FILE_PATH;
    OpusRecorderTask opusRecorderTask;
    private String recorderFilePath;
    private String recorderPcmFilePath;
    private String recorderDecodedPcmFilePath;
    private AudioManager audioManager;
    private int permissionRequestCode;

    @SuppressLint("NewApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        checkPermission();

    }

    private void checkPermission(){
        if(ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED ||
                ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ||
                ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED){
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO}, 1);
        }else{
            Log.d(TAG, "HAS PERMISSION");
        }
    }

    public void onCameraSurfaceViewShowClick(View view) {
        startActivity(new Intent(this,CameraSurfaceViewShowActivity.class));
    }

    public void onCameraTextureViewShowClick(View view) {
        startActivity(new Intent(this,CameraTextureViewShowActivity.class));
    }

    public void onCameraGlSurfaceShowClick(View view) {
        startActivity(new Intent(this,CameraGlSurfaceShowActivity.class));
    }

    public void onMyTextureViewClick(View view) {
        startActivity(new Intent(this,MyTextureViewActivity.class));
    }

    public void onOneOpenGlClick(View view) {
        startActivity(new Intent(this,OneOpenGlActivity.class));
    }

    public void onCustomGlViewClick(View view) {
        startActivity(new Intent(this,CustomGLViewActivity.class));
    }

    public void onNativeCameraShowClick(View view) {
        startActivity(new Intent(this,NativeCamActivity.class));
    }

    public void onNativeCameraRtcShowClick(View view) {
        startActivity(new Intent(this,NativeRtcActivity.class));
    }

    public void onNativeCameraSfuShowClick(View view) {
        startActivity(new Intent(this,NativeSfuActivity.class));
    }

    public void onNativeCameraSfu2ShowClick(View view) {
        startActivity(new Intent(this,NativeSfuActivity.class));
    }

    public void onCameraHelperShowClick(View view) {
        startActivity(new Intent(this,CameraHelperActivity.class));
    }
}